/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import java.util.Random;

import junit.framework.TestCase;





/**
 * Performs Validation Test for url validations.
 *
 * @version $Revision: 1128446 $ $Date: 2011-05-27 13:29:27 -0700 (Fri, 27 May 2011) $
 */
public class UrlValidatorTest extends TestCase {

   private boolean printStatus = false;
   private boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using.

   public UrlValidatorTest(String testName) {
      super(testName);
   }

   
   
   public void testManualTest()
   {
	   UrlValidator urlVal = new UrlValidator(null, null, UrlValidator.ALLOW_ALL_SCHEMES);
	   System.out.println(urlVal.isValid("http://www.amazon.com"));

	   
   }
   
   
   public void testYourFirstPartition()
   {
	   
   }
   
   public void testYourSecondPartition(){
	   
   }
   
   public void testIsValid()
   {
	   UrlValidator urlVal = new UrlValidator(null, null, UrlValidator.ALLOW_ALL_SCHEMES);

	   //arr to pull from, for alpha-plus-dot string
	   char[] chars = "abcdefghijklmnopqrstuvwxyz.".toCharArray();
	   
	   //arr to pull from, for port numbers at the end
	   char[] nums = "0123456789".toCharArray();
	   
	   //build strings
	   for(int i = 0;i<10000;i++)
	   {
		   StringBuilder sb = new StringBuilder();
		   Random random = new Random();

		   //generate prefix of the string (...the "scheme"?)
		   int Min = 3;
		   int Max = 4; 
		   int prefix = (Min + (int)(Math.random() * ((Max - Min) + 1)));
		   if (prefix == 3)
			   sb.append("ftp://");
		   else
			   sb.append("http://");

		   //test string body (the part after the double-slashes)
		   for (int x = 0; x < 20; x++) {
			   char c = chars[random.nextInt(chars.length)];
			   sb.append(c);
		   }
		   
		   //test the dot-whatever suffix at the end
		   sb.append(".");
		   //randomize the suffix length between 2 and 3
		   Min = 2;
		   Max = 3; 
		   int suffixlength = (Min + (int)(Math.random() * ((Max - Min) + 1)));		   
		   for (int y = 0; y < suffixlength; y++) {
			   char c = chars[random.nextInt(chars.length)];
			   sb.append(c);
		   }
		   
		   //test ports (using only 4 digits for now, to try and get some legit output)
		   sb.append(":");
		   //randomize port
		   for (int z = 0; z < 4; z++) {
			   char n = nums[random.nextInt(nums.length)];
			   sb.append(n);
		   }

		   //form Voltron
		   String output = sb.toString();

		   //and test...
		   System.out.println("Testing " + output + "  ...  ");
		   boolean answer = urlVal.isValid(output);
		   System.out.println(answer);
	   }
   }
   
   public void testAnyOtherUnitTest()
   {
	   
   }
   /**
    * Create set of tests by taking the testUrlXXX arrays and
    * running through all possible permutations of their combinations.
    *
    * @param testObjects Used to create a url.
    */
   

}
